﻿using System.Data;
using System.Data.Odbc;

namespace crm.model
{
    public class LeadsDao : Conexao
    {
        Conexao c = new Conexao();

        public bool inserir(Leads obj)
        {
            colParams.Clear();
            string query = "insert into leads (nome, empresa, email, telefone, fkidorigemleads, observacao, fkidstatus) values (?,?,?,?,?,?,?);";
            colParams.Add(new OdbcParameter("@nome", obj.Nome));
            colParams.Add(new OdbcParameter("@empresa", obj.Empresa));
            colParams.Add(new OdbcParameter("@email", obj.Email));
            colParams.Add(new OdbcParameter("@telefone", obj.Telefone));
            colParams.Add(new OdbcParameter("@fkidorigemleads", obj.FkIdOrigemLeads));
            colParams.Add(new OdbcParameter("@observacao", obj.Observacao));
            colParams.Add(new OdbcParameter("@fkidstatus", obj.status));
            return c.Executar(query,colParams);
        }

        public DataTable consultar()
        {
            string query = "select * from vw_leads";
            return c.ExecutarConsulta(query);
        }

        public DataTable consultar(int id)
        {
            colParams.Clear();
            string query = "select * from leads where idleads = ?;";
            colParams.Add(new OdbcParameter("@idleads", id));
            return c.ExecutarConsulta(query,colParams);
        }

        public DataTable consultar(string nome)
        {
            colParams.Clear();
            string query = "select * from leads where nomeLeads like ?;";
            colParams.Add(new OdbcParameter("@nome", nome));
            return c.ExecutarConsulta(query);
        }

        public bool atualizar(Leads obj)
        {
            colParams.Clear();
            string query = "update leads set nomeleads = ? where idLeads = ?;";
            colParams.Add(new OdbcParameter("@nomeleads", obj.Nome));
            colParams.Add(new OdbcParameter("@idleads", obj.IdLeads));
            return c.Executar(query,colParams);
        }

        public bool remover(int id)
        {
            colParams.Clear();
            string query = "update leads set status = 1 where idleads = ?;";
            colParams.Add(new OdbcParameter("@idleads", id));
            return c.Executar(query,colParams);
        }
    }
}
